﻿using MvcSimplyCleverPart3.Models;
using System.Web.Mvc;

namespace MvcSimplyCleverPart3
{
    public class SetDefaultValueAttribute : ActionFilterAttribute
    {
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            AddressViewModel address = filterContext.Controller.ViewData.Model as AddressViewModel;
            
            if(address == null)
            {
                address = new AddressViewModel();
                address.CountryCode = "US";
                address.StateCode = "CA";
                filterContext.Controller.ViewData.Model = address;
            }
        }
    }
}